package com.qjcc.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;
import java.util.Map;

public class SeriesInclude extends Series {

    private double pointPadding = 0.4;
    private double pointPlacement;

    private SeriesInclude(Builder builder){
        setName(builder.name);
        setType(builder.type);
        setyAxis(builder.yAxis);
        setData(builder.data);
        setTooltip(builder.tooltip);
        this.pointPadding = builder.pointPadding;
        this.pointPlacement = builder.pointPlacement;
    }

    public static class Builder {
        private String name;
        private String type;
        private int yAxis = 0;
        private List<Double> data;
        private Map<String, String> tooltip;
        private double pointPadding = 0.4;
        private double pointPlacement;

        public Builder name(String name){
            this.name = name;
            return this;
        }

        public Builder type(String type){
            this.type = type;
            return this;
        }

        public Builder yAxis(int yAxis){
            this.yAxis = yAxis;
            return this;
        }

        public Builder data(List data){
            this.data = data;
            return this;
        }

        public Builder tooltip(Map tooltip){
            this.tooltip = tooltip;
            return this;
        }

        public Builder pointPadding(double pointPadding){
            this.pointPadding = pointPadding;
            return this;
        }

        public Builder pointPlacement(int index){
            this.pointPlacement = SeriesInclude.getPointPlacementByArray(index);
            return this;
        }

        public SeriesInclude build(){
            return new SeriesInclude(this);
        }

    }

    /**
     * 设置pointPlacement，从数组中取值
     * @param index
     */
    public static double getPointPlacementByArray(int index){
        return pointPlacementArray[index];
    }

    /**
     * 这里默认是每条数据组中包含5种数据
     */
    @JsonIgnore
    private static double[] pointPlacementArray = {-0.3, -0.1, 0.1, 0.3, 0};

    public double getPointPadding() {
        return pointPadding;
    }

    public void setPointPadding(double pointPadding) {
        this.pointPadding = pointPadding;
    }

    public double getPointPlacement() {
        return pointPlacement;
    }

    public void setPointPlacement(double pointPlacement) {
        this.pointPlacement = pointPlacement;
    }

    public double[] getPointPlacementArray() {
        return pointPlacementArray;
    }

    public void setPointPlacementArray(double[] pointPlacementArray) {
        this.pointPlacementArray = pointPlacementArray;
    }



    public static void main(String[] args) {
        SeriesInclude.Builder builder = new SeriesInclude.Builder();
        SeriesInclude d = builder.name("name").pointPadding(1.2).build();
        System.out.println(d);
    }

}
